<!--
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-21 16:25:23
 * @LastEditTime: 2022-11-05 11:24:20
-->
<template>
  <div class="delivery-msg">
    <div class="flex flex-horizontal-between flex-vertical-center">
      <p class="title">交房信息</p>
      <Button type="primary" v-if="deliveryShow" @click="deliveryFun">交房</Button>
      <Button type="primary" v-if="deliveryEditShow" @click="deliveryFun">修改交房</Button>
    </div>
    <div class="table-delivery">
      <Table :columns="columns" :data="data" border></Table>
    </div>
    <!--交房管理-->
    <delivery-operate ref="deliveryOperate" @onGetOrderDetail="refreshOrderDetail">
    </delivery-operate>
  </div>
</template>
<script>
  import deliveryOperate from '../components/deliveryOperate.vue'
  export default {
    props: ['detailMsg', 'orderStatusName', 'contractId'],
    data() {
      return {
        // '签约回款中', '签约已全款' 可交房操作  
        // 签约已交房  可修改交房操作
        deliveryShow: false,
        deliveryEditShow: false,
        columns: [
        {
          title: '交房人',
          key: 'principalName',
        },
        {
          title: '交房日期',
          key: 'handRoomDate',
        },
        {
          title: '交房奖金占比（%）',
          key: 'divideInto',
        }],
        data: []
      }
    },
    components: {
      deliveryOperate,
    },
    mounted() {
      this.data = this.detailMsg.divideRooms
      let statusName = this.detailMsg.orContractBaseInfoVO.statusName
      this.deliveryShow =
        this.orderStatusName == '签约' ? ['签约回款中', '签约已全款'].indexOf(statusName) > -1 &&
        this.unlocking('0104030310') && !this.detailMsg.divideRooms.length :
        false

      this.deliveryEditShow =
        this.orderStatusName == '签约' ? ['签约已交房', '签约回款中', '签约已全款'].indexOf(statusName) > -1 &&
        this.unlocking('0104030310') && this.detailMsg.divideRooms.length :
        false

      let showDeliveryModal = this.$dt.memory.get('showDeliveryModal')
      if (showDeliveryModal && this.$route.params.showDeliveryModal) {
        this.deliveryFun()
      }
    },
    methods: {
      deliveryFun() {
        console.log('交房')
        this.$refs.deliveryOperate.show(this.contractId, this.deliveryEditShow, this.detailMsg
          .divideRooms)
      },
      // 刷新详情数据
      refreshOrderDetail() {
        this.$dt.memory.set('showDeliveryModal', false)
        this.$emit('onGetOrderDetail')
      },
    },
  }
</script>
<style lang="scss" scoped>
  .delivery-msg {
    margin-top: 40px;

    .table-delivery {
      margin-top: 20px;
    }
  }
</style>